<?php

use Overtrue\Pinyin\Pinyin;

class Lib_Pinyin
{
    private static $obj;

    private function __construct()
    { }

    /**
     * Undocumented function
     * @return Lib_Pinyin
     */
    public static function getInstance()
    {
        if (is_null(self::$obj)) {
            self::$obj = new self();
        }

        return self::$obj;
    }

    public function __clone()
    { }
    public function convert($text)
    {
        $pinyin = new Pinyin('Overtrue\Pinyin\MemoryFileDictLoader'); // 使用内存加载字典

        return implode(' ', $pinyinText = $pinyin->convert($text, PINYIN_TONE));
    }

}
